package com.entity;

import com.util.GameUtil;
import com.view.GameFrame;

import java.awt.*;

/**
 * @author: Combo
 * @time: 2021/1/4 15:04
 * @description: 障碍物 —— 螃蟹
 */
public class Crab {
    private Image image;
    private Image[] images;
    public static final int WIDTH = 100;
    public static final int HEIGHT = 110;
    private Integer x;
    private Integer y;
    private Integer index;
    private Integer speed;

    public Crab() {
        images = new Image[2];
        images[0] = GameUtil.getImage("images/crab/crab1.png");
        images[1] = GameUtil.getImage("images/crab/crab2.png");
        image = images[0];
        x = GameFrame.WIDTH + 100;
        y = 580;
        speed = 30;
        index = 0;
    }

    /**
     * 螃蟹移动
     */
    public void step(){
        image = images[index++ / 5 % images.length];
        x -= speed;
    }

    /**
     * 画螃蟹
     * @param g
     */
    public void paintCrab(Graphics g){
        g.drawImage(image, x, y , WIDTH, HEIGHT, null);
    }

    /**
     * 越界判断
     * @return
     */
    public boolean outOfBounds(){
        return this.x <= -WIDTH;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image[] getImages() {
        return images;
    }

    public void setImages(Image[] images) {
        this.images = images;
    }

    public static int getWIDTH() {
        return WIDTH;
    }

    public static int getHEIGHT() {
        return HEIGHT;
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getSpeed() {
        return speed;
    }

    public void setSpeed(Integer speed) {
        this.speed = speed;
    }
}
